<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>表单输入绑定</h2>
      <input type="text" :value="msg" @input="fn" />
      <p>msg: {{ msg }}</p>

      <hr />

      <h3>input的绑定</h3>
      <p>Message is: {{ message }}</p>
      <input v-model="message" placeholder="edit me" />

      <h3>textArea的绑定</h3>
      <textarea v-model="textarea"></textarea>
      <p>areaMsg: {{ textarea }}</p>

      <h3>复选框</h3>
      <!-- 当只有一个复选框绑定了这个变量，这个变量会变成布尔值 -->
      <input
        type="checkbox"
        v-model="checkValue"
        true-value="yes"
        false-value="no"
      />我已阅读此条款
      <p>checkValue: {{ checkValue }}</p>

      <br />
      <!-- 当有多个复选框同时绑定了一个变量，这个变量会自动变成数组 -->
      <input type="checkbox" v-model="likes" value="sing" />唱
      <input type="checkbox" v-model="likes" value="jump" />跳
      <input type="checkbox" v-model="likes" value="rap" />rap
      <p>likes: {{likes}}</p>

      <h3>单选框</h3>
      <input type="radio" v-model="sex" value="1" />男
      <input type="radio" v-model="sex" value="2" />女
      <input type="radio" v-model="sex" value="3" />未知
      <p>sex: {{sex}}</p>

      <h3>下拉框</h3>
      <select v-model="selected">
        <option disabled value="">Please select one</option>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="3">C</option>
      </select>
      <p>selected: {{ selected }}</p>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const app = createApp({
        data() {
          return {
            msg: "123",
            message: "",
            textarea: "",
            checkValue: true,
            likes: ["jump"],
            sex: "",
            selected: "",
          };
        },
        methods: {
          fn(e) {
            this.msg = e.target.value;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
